package com.charzhan.five;

import com.charzhan.utiles.rabbitmqutil;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

public class ReciveLog {
    public static final String EXCHANGE_NAME="logs";
    public static void main(String[] args) throws  Exception {
        Channel channel = rabbitmqutil.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");

        //声明一个临时队列
        //当消费者断开的时候，就
        String queue = channel.queueDeclare().getQueue();
        // 捆绑队列
        channel.queueBind(queue,EXCHANGE_NAME,"");
        System.out.println("等待接手消息0");
        DeliverCallback deliverCallback =(consumerTag,message)->{
            System.out.println(new String(message.getBody()));
        };
        CancelCallback cancelCallback=(consumerTag)->{
            System.out.println(consumerTag);
        };

        channel.basicConsume(queue,true,deliverCallback,cancelCallback);
    }
}
